package com.taotao.job.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;
import com.google.common.base.Preconditions;
import com.taotao.job.dao.JobDagEdgeMapper;
import com.taotao.job.model.entity.JobDagEdge;
import com.taotao.job.service.JobDagEdgeService;
import com.taotao.job.util.EntityUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.Set;

/**
 * <p>
 * 有向无环图的边服务接口实现类
 * </p>
 *
 * @author Fan Beibei
 * @version V1.0
 * @since 2021-03-14 21:43:18
 */
@Slf4j
@Service
public class JobDagEdgeServiceImpl implements JobDagEdgeService {
    @Resource
    private JobDagEdgeMapper jobDagEdgeMapper;


    @Override
    public void softDelByIds (Set<java.lang.Long> ids, Long userId) {
        Preconditions.checkArgument(null != ids && ids.size() > 0);
        Preconditions.checkArgument(null != userId);

        jobDagEdgeMapper.softDelByPks(ids,userId,new Date());
    }

    @Override
    public JobDagEdge queryById (java.lang.Long id) {
        Preconditions.checkArgument(null != id);

        return jobDagEdgeMapper.selectByPk(id);
    }

    @Override
    public void addOrUpdate(JobDagEdge jobDagEdge, Long userId) {
        Preconditions.checkArgument(null != jobDagEdge);
        Preconditions.checkArgument(null != userId);

        if (null == jobDagEdge.getId()) {
            EntityUtils.setPo5Field(userId, new Date(), jobDagEdge);
            jobDagEdgeMapper.insert(jobDagEdge);
        } else {
            EntityUtils.setPo2Field(userId, new Date(), jobDagEdge);
            //这里不做删除
            jobDagEdge.setIsDel(null);
            jobDagEdgeMapper.updateByPk(jobDagEdge);
        }

    }

    @Override
    public PageInfo<JobDagEdge> queryByPage(JobDagEdge param, int pageNum, int pageSize) {
        Preconditions.checkArgument(pageNum > 0);
        Preconditions.checkArgument(pageSize > 0);

        Page<JobDagEdge> page =  jobDagEdgeMapper.selectByPage(param,pageNum,pageSize);

        return new PageInfo<>(page);
    }






//------------以上是生成代码-----------------------------------------------------------------------------------------------------------------









}
